import React from 'react';
import {Checkbox, Select} from 'antd';
import selectorData from "share/selectorData";
import {messages} from "share/common";
import moment from "moment/moment";
const Option = Select.Option;

export default {
  formTypes:[
    {label:messages('common.all')/*全部*/, value:'All'},
    {label:messages('supplier-1.key5')/*退改签表单*/, value:'8001'},
    {label:messages('supplier-1.key6')/*机票二次审批单*/, value:'8002'},
    {label:messages('supplier-1.key7')/*酒店二次审批*/, value:'8003'},
  ],

  statusOptions: [
    {label:messages('supplier-1.key8')/*审批中*/, value:'1001'},
    {label:messages('supplier-1.key9')/*已通过*/, value:'1002'},
    {label:messages('supplier-1.key10')/*已驳回*/, value:'1003'},
  ],

  //********************************************************************************************************************

  getGeneralViewSearchForm(){
    const searchForm = [
      {
        component: 'Select',
        id: 'formType',
        props: {
          style: {width: '100%'},
        },
        label: messages('common.document.name')/*单据名称*/,
        children: this.formTypes.map(item => <Option key={item.value}>{item.label}</Option>),
        initialValue: 'All',
        parser: value => ({
          formType: value === 'All' ? '' : value,
        }),
        tagParser: (value) => this.tagParseFormat(value, this.formTypes),
      },
      {
        component: 'Selector',
        id: 'userOID',
        label: messages('supplier-1.key11')/*申请人姓名/工号*/,
        props: {
          placeholder: messages('common.please.input')/*请输入*/ + messages('supplier-1.key11')/*申请人姓名/工号*/,
          selectorItem: {
            ...selectorData['user'],
            url: `/api/users/v3/search?page=0&size=9999&roleType=TENANT&status=all`,
            label: record => (`${record.employeeID}-${record.fullName}${(record.status !== 1001 ?
                (`（${record.status === 1002 ?
                    messages('supplier-1.key12')/*待离职员工*/ :
                    messages('supplier-1.key13')/*离职员工*/}）`
                ) :
                ''
            )}`)
          }
        },
      },
      {
        component: 'DateRangePicker',
        id: 'submittedDate',
        label: messages('common.submit.date')/*提交日期*/,
        initialValue: [moment().subtract(1, 'month'), moment()],
        parser: value => ({
          beginDate: value && value[0] ? moment(value[0]).format('YYYY-MM-DD') : null,
          endDate: value && value[1] ? moment(value[1]).format('YYYY-MM-DD') : null
        }),
      },
      {
        component: (
          <Checkbox.Group>
            {
              this.statusOptions.map(item => <Checkbox key={item.value} value={item.value}>{item.label}</Checkbox>)
            }
          </Checkbox.Group>
        ),
        id: 'statusList',
        label: messages('common.column.status')/*状态*/,
        tagParser: (value) => this.tagParseFormat(value, this.statusOptions),
        row: true,
      }
    ];
    return searchForm;
  },

  //***************************************************************************************************************
  tagParseFormat(value, arr) {
    let label = '';
    arr.map(item => {
      if (item.value === value) {
        label = item.label;
      }
    });
    return label;
  },
}
